document.write("<!--login start-->\n" +
    "    <div class=\"modal fade\" id=\"sign-modal\" tabindex=\"-1\" role=\"dialog\">\n" +
    "    <div class=\"modal-dialog modal-sm\" role=\"document\">\n" +
    "        <div class=\"modal-content\">\n" +
    "            <button type=\"button\" class=\"close-modal\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\n" +
    "            <div class=\"modal-body\">\n" +
    "                <ul class=\"nav nav-tabs\" role=\"tablist\">\n" +
    "                    <li role=\"presentation\" class=\"active\">\n" +
    "                        <a href=\"#signin-form\" aria-controls=\"signin-form\" role=\"tab\" data-toggle=\"tab\">登录</a>\n" +
    "                    </li>\n" +
    "                    <li role=\"presentation\">\n" +
    "                        <a href=\"#signup-form\" aria-controls=\"signup-form\" role=\"tab\" data-toggle=\"tab\">注册</a>\n" +
    "                    </li>\n" +
    "                </ul>\n" +
    "                <div class=\"tab-content\">\n" +
    "                    <div role=\"tabpanel\" class=\"tab-pane active\" id=\"signin-form\">\n" +
    "                        <form action=\"#\" >\n" +
    "                            <div class=\"form-group\">\n" +
    "                                <div class=\"input-group\">\n" +
    "                                    <div class=\"input-group-addon\">\n" +
    "                                        <i class=\"glyphicon glyphicon-phone\" style=\"margin:0;\"></i>\n" +
    "                                    </div>\n" +
    "                                    <input type=\"text\"  id=\"telephone\" class=\"form-control\" placeholder=\"请输入手机号\">\n" +
    "                                </div>\n" +
    "                            </div>\n" +
    "                            <div class=\"form-group\">\n" +
    "                                <div class=\"input-group\">\n" +
    "                                    <div class=\"input-group-addon\">\n" +
    "                                        <i class=\"fa fa-lock\" style=\"margin:0;\"></i>\n" +
    "                                    </div>\n" +
    "                                    <input type=\"password\" id=\"password\" class=\"form-control\" placeholder=\"请输入密码\">\n" +
    "\n" +
    "                                </div>\n" +
    "                            </div>\n" +
    "                            <div class=\"form-inline verify-code-item\">\n" +
    "                                <div class=\"form-group\">\n" +
    "                                </div>\n" +
    "\n" +
    "                            </div>\n" +
    "                            <div class=\"form-group remember-login\">\n" +
    "                                <input name=\"remember\" type=\"checkbox\" value=\"y\"> 下次自动登录\n" +
    "                                <a class=\"pull-right\" href=\"reset_password/index.html\">忘记密码？</a>\n" +
    "                            </div>\n" +
    "\n" +
    "                            <div class=\"form-group\">\n" +
    "                                <input class=\"btn btn-primary\" name=\"submit\" type=\"button\" value=\"进入education\" onclick=\"httplogin()\">\n" +
    "                            </div>\n" +
    "                            <div class=\"form-group error-msg\">\n" +
    "                                <div class=\"alert alert-danger\" role=\"alert\"></div>\n" +
    "                            </div>\n" +
    "                        </form>\n" +
    "\n" +
    "                    </div>\n" +
    "                    <div role=\"tabpanel\" class=\"tab-pane\" id=\"signup-form\">\n" +
    "                        <form action=\"#\" >\n" +
    "                            <div class=\"form-group\">\n" +
    "                                <div class=\"input-group\">\n" +
    "                                    <div class=\"input-group-addon\">\n" +
    "                                        <i class=\"glyphicon glyphicon-phone\" style=\"margin:0;\"></i>\n" +
    "                                    </div>\n" +
    "                                    <input type=\"text\" id=\"telephoneR\" class=\"form-control\" placeholder=\"请输入手机号\">\n" +
    "                                </div>\n" +
    "                            </div>\n" +
    "                            <div class=\"form-group\">\n" +
    "                                <div class=\"input-group\">\n" +
    "                                    <div class=\"input-group-addon\">\n" +
    "                                        <i class=\"fa fa-lock\" style=\"margin:0;\"></i>\n" +
    "                                    </div>\n" +
    "                                    <input type=\"password\" id=\"passwordR\" class=\"form-control\" placeholder=\"请输入密码\" required=\"required\" maxlength=\"16\">\n" +
    "                                    <span onclick=\"dj()\" class=\"glyphicon glyphicon-eye-close form-control-feedback-my\"></span>\n" +
    "                                    <!--小图标元素-->\n" +
    "                                </div>\n" +
    "                            </div>\n" +
    "                            <div class=\"form-inline\">\n" +
    "                                <div class=\"form-group\">\n" +
    "                                    <div class=\"input-group\" style=\"width: 300px;float: left\">\n" +
    "                                        <input id=\"veryCode\" name=\"veryCode\" type=\"text\" class=\"form-control\" placeholder=\"请输入验证码\" style=\"width: 160px\">\n" +
    "                                        <input type=\"button\" value=\"点击获取验证码\" onclick=\"getCode()\" style=\"width: 120px;float: left;margin-left: 20px\">\n" +
    "                                    </div>\n" +
    "                                </div>\n" +
    "                            </div>\n" +
    "                            <div class=\"form-group\">\n" +
    "                                <input class=\"btn btn-primary\" name=\"submit\" type=\"button\" value=\"注册\" onclick=\"reg()\">\n" +
    "                            </div>\n" +
    "                            <div class=\"form-group agree-privacy\">\n" +
    "                                注册表示您已经同意我们的<a href=\"privacy/index.html\" target=\"_blank\">隐私条款</a>\n" +
    "                            </div>\n" +
    "                            <div class=\"form-group error-msg\">\n" +
    "                                <div class=\"alert alert-danger\" role=\"alert\"></div>\n" +
    "                            </div>\n" +
    "                        </form>\n" +
    "                    </div>\n" +
    "                </div>\n" +
    "            </div>\n" +
    "        </div>\n" +
    "    </div>\n" +
    "\n" +
    "</div>\n" +
    "<!--login end-->")




//
// //点击换一张验证码
// function changeImg() {
//     var imgSrc = $("#imgObj");
//     var src = imgSrc.attr("src");
//     imgSrc.attr("src", chgUrl(src));
// }
//时间戳
//为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
// function chgUrl(url) {
//     var timestamp = (new Date()).valueOf();
//     urlurl = url.substring(0, 17);
//     if ((url.indexOf("&") >= 0)) {
//         urlurl = url + "×tamp=" + timestamp;
//     } else {
//         urlurl = url + "?timestamp=" + timestamp;
//     }
//     return urlurl;
// }


//点击发送验证码
function getCode() {

    //手机正则表达式
    let telephoneRVal = $("#telephoneR").val();
    if (!(/^1[3456789]\d{9}$/.test(telephoneRVal))) {
        alert("手机号码不合法，请重新输入");
        return false;

    } else {
        //将手机号存储到全局变量中,以便比对获取验证码后手机号有没有改变
        {
            mobile=telephoneRVal
        }

        //手机号合法请求获取验证码
        $.ajax({
            xhrFields:{
                withCredentials:true
            },
            type: "GET",
            url: "http://localhost:9091//education_api/user/code",
            data: {
                telephone: telephoneRVal
            },
            success: function (resp) {
                let result = resp;
                if (typeof resp != "object") {
                    result = JSON.parse(resp);
                }
                if (result.code == 0) {
                    //业务数据
                    let data = result.data;
                    console.log(data);
                } else {
                    //返回错误原因
                    alert(result.message);

                }
            }
        });


    }
}

//注册请求
function reg() {
    let val = $("#loginJump").val();
    console.log(val);
    //手机正则表达式
    let telephoneRVal = $("#telephoneR").val();
    if (!(/^1[3456789]\d{9}$/.test(telephoneRVal))) {
        alert("手机号码不合法，请重新输入");
        return false;

    }
    if (telephoneRVal!=mobile){
        alert("亲，您的手机号有变哦");
        return false;

    } else {
        let passwordRVal = $("#passwordR").val();
        let codeVal = $("#veryCode").val();
        console.log(codeVal);


        $.ajax({
            xhrFields:{
                withCredentials:true
            },
            type: "POST",
            url:  baseUrl+"/education_api/user/register",
            data: {
                telephone: telephoneRVal,
                password: passwordRVal,
                code: codeVal
            },
            success: function (resp) {
                let result = resp;
                if (typeof resp != "object") {
                    result = JSON.parse(resp);
                }
                if (result.code==0){
                    //业务数据
                    let data = result.data;
                    //不同的业务数据对应不同的方法
                    alert(data);
                    $("#registerJump")[0].style.display="none";//隐藏
                    location.reload();
                    $("#loginJump").click();

                } else {
                    //返回错误原因
                    alert(result.message);

                }
            }
        });

    }


}

//登录请求
function httplogin() {
    let telephoneVal = $("#telephone").val();
    let passwordVal = $("#password").val();
    console.log(telephoneVal);
    console.log(passwordVal);
    $.ajax({
        xhrFields:{
            withCredentials:true
        },
        type: "POST",
        data:{
            telephone: telephoneVal,
            password: passwordVal
        },
        url: baseUrl+"education_api/user/login",
        success: function (resp) {
            let result = resp;
            if (typeof resp != "object") {
                result = JSON.parse(resp);
            }
            if (result.code==0){
                let data=result.data;
                console.log(data);
                //将JSON转为字符串存到变量里
                users = JSON.stringify(data);
                console.log("JSON-user:"+users);
                //将变量存到localStorage里
                sessionStorage.setItem("User",users);
                location.reload();
            } else {
                alert(result.message)
            }
        }
    });
}

//点击查看密码
function dj() {
    //点击眼睛，如果input输入框为为text时执行，并改成password实现隐藏。
    if ($("#passwordR").attr("type") == "text") {
        $("#passwordR").attr("type", "password");

    }
    //点击眼睛，如果input输入框为为password时执行，并改成text实现隐藏。
    else {
        $("#passwordR").attr("type", "text");

    }
}



